/*
 * Copyright 2018 Dash Core Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This file was generated by SWIG (http://www.swig.org) and modified.
 * Version 3.0.12
 */

package org.dashj.bls;

import com.google.common.base.Preconditions;

public class InsecureSignature extends BLSObject {

  protected InsecureSignature(long cPtr, boolean cMemoryOwn) {
    super(cPtr, cMemoryOwn);
  }

  protected static long getCPtr(InsecureSignature obj) {
    return (obj == null) ? 0 : obj.cPointer;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    JNI.delete_InsecureSignature(cPointer);
  }

  public static InsecureSignature FromBytes(byte [] data) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(data.length == SIGNATURE_SIZE);
    return new InsecureSignature(JNI.InsecureSignature_FromBytes(data), true);
  }

  public static InsecureSignature FromG2(SWIGTYPE_p_g2_t element) {
    return new InsecureSignature(JNI.InsecureSignature_FromG2(SWIGTYPE_p_g2_t.getCPtr(element)), true);
  }

  public InsecureSignature(InsecureSignature signature) {
    this(JNI.new_InsecureSignature(InsecureSignature.getCPtr(signature), signature), true);
  }

  public boolean Verify(MessageHashVector hashes, PublicKeyVector pubKeys) {
    Preconditions.checkNotNull(hashes);
    Preconditions.checkNotNull(pubKeys);
    Preconditions.checkArgument(hashes.size() == pubKeys.size(), "hashes and public keys  must be of the same size");
    Preconditions.checkArgument(hashes.size() > 0, "hashes and public keys must be at least 1");
    return JNI.InsecureSignature_Verify(cPointer, this, MessageHashVector.getCPtr(hashes), PublicKeyVector.getCPtr(pubKeys), pubKeys);
  }

  public boolean Verify(byte [] hash, PublicKey pubKey) {
    Preconditions.checkNotNull(hash);
    Preconditions.checkNotNull(pubKey);
    PublicKeyVector pubKeys = new PublicKeyVector();
    pubKeys.push_back(pubKey);
    MessageHashVector hashes = new MessageHashVector();
    hashes.push_back(hash);
    return Verify(hashes, pubKeys);
  }

  public static InsecureSignature Aggregate(InsecureSignatureVector sigs) {
    Preconditions.checkNotNull(sigs);
    Preconditions.checkArgument(sigs.size() > 0);
    return new InsecureSignature(JNI.InsecureSignature_Aggregate(InsecureSignatureVector.getCPtr(sigs)), true);
  }

  public InsecureSignature DivideBy(InsecureSignatureVector sigs) {
    Preconditions.checkNotNull(sigs);
    Preconditions.checkArgument(sigs.size() > 0);
    return new InsecureSignature(JNI.InsecureSignature_DivideBy(cPointer, this, InsecureSignatureVector.getCPtr(sigs)), true);
  }

  public void Serialize(byte[] buffer) {
    Preconditions.checkNotNull(buffer);
    Preconditions.checkArgument(buffer.length >= SIGNATURE_SIZE);
    JNI.InsecureSignature_Serialize__SWIG_0(cPointer, this, buffer);
  }

  public byte [] Serialize() {
    byte [] bytes = new byte[(int)SIGNATURE_SIZE];
    Serialize(bytes);
    return bytes;
  }

  @Override
  public String toString() {
    return "InsecureSignature(" + Utils.HEX.encode(Serialize()) + ")";
  }

  public final static long SIGNATURE_SIZE = JNI.InsecureSignature_SIGNATURE_SIZE_get();
}
